import 'package:json_annotation/json_annotation.dart';
import 'package:kq_flutter_core_widget/network/field_convert.dart';

part 'drop_down_option.g.dart';

@JsonSerializable(converters: nullFieldConvertList)
class DropDownOption {
  String? title;
  String? titleId;
  ///是否选中
  @JsonKey(includeToJson: false, includeFromJson: false)
  bool chosen = false;

  DropDownOption(this.title, this.titleId);

  factory DropDownOption.fromJson(Map<String, dynamic> json) {
    dynamic name = json.remove("name");
    json.putIfAbsent("title", () => name);
    dynamic dropId = json.remove("dropid");
    json.putIfAbsent("titleId", () => dropId);
    return _$DropDownOptionFromJson(json);
  }

  static List<DropDownOption> fromJsonList(List<dynamic> json) => json
      .map((e) => DropDownOption.fromJson(e as Map<String, dynamic>))
      .toList();

  @override
  int get hashCode => titleId.hashCode;

  @override
  bool operator ==(other) =>
      other is DropDownOption && titleId == other.titleId;
}
